<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="/lib/layui/css/layui.css"  media="all">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>

<div class="layui-btn-group demoTable">
    <button class="layui-btn" data-type="getCheckData" id="del">删除</button>
</div>

<table class="layui-hide" id="test" lay-filter="test"></table>

<!--<script type="text/html" id="barDemo">-->
<!--    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>-->
<!--</script>-->


<script src="/lib/layui/layui.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->

<script>
    layui.use('table', function(){
        var table = layui.table;
        var $ = layui.jquery;

        var userTable = table.render({
            elem: '#test'
            ,url:'/orders/findOrderAll.do'
            ,toolbar: '#toolbarDemo'
            ,title: '用户数据表'
            ,cols: [[
                {type: 'checkbox', fixed: 'left'}
                ,{field:'id', title:'ID',  fixed: 'left', unresize: true, sort: true, }
                ,{field:'goodsId', title:'商品编号',  edit: 'text'}
                ,{field:'goodsName', title:'商品名字',  sort: true}
                ,{field:'goodsPrice', title:'商品价格',  edit: 'text', sort: true}
                ,{field:'goodsNum', title:'商品数量',  sort: true, totalRow: true}
                ,{field:'createBy', title:'创建人'}
                ,{field:'createTime', title:'创建时间',templet : "<div>{{layui.util.toDateString(d.createTime, 'yyyy-MM-dd HH:mm:ss')}}</div>"}
                ,{field:'lastUpdateTime', title:'修改时间',templet : "<div>{{layui.util.toDateString(d.lastUpdateTime, 'yyyy-MM-dd HH:mm:ss')}}</div>"}
                ,{fixed: 'right', title:'操作', toolbar: '#barDemo'}
            ]]
            ,page: true
            ,limit:5
            ,limits:[5,10,15,20,25]
            ,done:function (rec) {
                if (rec.code === 2) {
                    layer.msg("无权访问购物车", {icon: 5, time: 1500},function () {
                        window.location.href = "/html/welcome.html?t=1";
                    });
                }
            }
        });


        $("#del").on("click",function () {
            var checkStatus = table.checkStatus("test");
            var data = checkStatus.data;
            var isid = [];
            data.forEach(function (d) {
                isid.push(d.id)
            })
            console.log(isid)

            layer.confirm("确认删除吗", function (index) {
                $.ajax({
                    url: "/orders/delOrders.do",
                    data: {"isid": isid},
                    type: "post",
                    traditional: true,
                    dataType: "json",
                    success: function (rec) {
                        if (rec.code == 0) {
                            layer.msg('删除成功');
                            userTable.reload({
                                page: {curr: 1}
                            });
                        } else {
                            layer.msg('删除失败');
                        }
                    }
                });
                layer.close(index);
            });

        })


    });


    // else if (obj.event === 'delete') {  // 监听删除操作
    //     var checkStatus = table.checkStatus('currentTableId')
    //         , data = checkStatus.data;
    //     let ids = [];
    //     for (let x of data) {
    //         ids.push(x.id)
    //     }
    //     console.log(ids);







</script>

</body>
</html>